<?php

/**
 * AuthController
 * 
 * @author Maodo DIOP <dmaodo@gmail.com>
 * @version 
 */



class Admin_BassinderetentionController extends Zend_Controller_Action {
	
	public function indexAction() {
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
		
		$bassin = new Admin_Model_DbTable_Bassinderetention();
		$res = $bassin->getAllBassin();
		$resultat = Zend_Json :: encode($res);
		$this->_response->setBody($resultat);
	}
	
	public function addAction() {
		$this->view->title = "Ajouter nouveau bassin de retention";
		$this->view->headTitle($this->view->title);
		
		$form = new Admin_Form_Bassinderetention();
		
		$form->submit->setLabel('Ajouter');
		$this->view->form = $form;
		
		if ($this->getRequest()->isPost()) {
			$formData = $this->getRequest()->getPost();
			if ($form->isValid($formData)) {         
				$nombassin = $form->getValue('nombassin');
				$bassin = new Admin_Model_DbTable_Bassinderetention();
				$bassin->addBassinderetention($nombassin);               
				$this->_helper->redirector('index');
			} else {
				$form->populate($formData);
			}
		}
	}
	
	public function editAction() {
		$this->view->title = "Modifier bassin";
		$this->view->headTitle($this->view->title, 'PREPEND');
		
		$form = new Admin_Form_Bassinderetention() ;
		
		$form->submit->setLabel('Enregistrer');
		$this->view->form = $form;
		
		if ($this->getRequest()->isPost()) {
			$formData = $this->getRequest()->getPost();
			if ($form->isValid($formData)) {            	
				
				$idbassinderetention = (int)$this->_getParam('idbassinderetention');;             
				$nombassin = $form->getValue('nombassin');          
				
				$bassin = new Admin_Model_DbTable_Bassinderetention();
				$bassin->updateBassinderetention($idbassinderetention,$nombassin);          
				$this->_redirect('/admin/bassinderetention/index');
			} else {
				$form->populate($formData);
			}
		} else {
			//Si le formulaire n'est pas encore posté
			//Recuperer la valeur de l'objet à editer
			$idbassinderetention = $this->_request->getParam('idbassinderetention', 0);
			if ($idbassinderetention > 0) {
				$bassin = new Admin_Model_DbTable_Bassinderetention();
				$form->populate($bassin->getBassinderetention($idbassinderetention));
			}
		}   
	}
	
	
	public function deleteAction() {
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
		
		$idbassinderetention = $this->_getParam('idbassinderetention', 0);
		$bassin = new Admin_Model_DbTable_Bassinderetention();
		$bassin->deleteBassinderetention($idbassinderetention);
		$this->_redirect('/admin/bassinderetention/index');
	}
	
	public function allBassinderetentionAction() {
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->getHelper('layout')->disableLayout();
		
		$bassin = new Admin_Model_DbTable_Bassinderetention();
		$res = $bassin->getAllBassinderetention();
		$resultat = Zend_Json :: encode($res);
		$this->_response->setBody($resultat);
	}
	
}
